/*获取订单号*/
var orderId = sessionStorage.getItem("serviceProviderorderid");
var orderBaseId=sessionStorage.getItem("orderBaseIds");
var pushOrdererrorCode = 1//下推订单状态
var warehouses = ""
var wuliu = "";
var result11 = {}
var orderProofListid=""//审核表主键id
var uploadProofStatus=""
getAllWare()

function getAllWare() { //获取所有发货仓
    $.ajax({
        contentType: "application/json;charset=UTF-8",
        url: root.publics.queryWarehouseInfo,
        cache: false, //禁用缓存
        type: "POST",
        dataType: "json",
        async: false,//优先运行
        data: JSON.stringify({
            warehouseCode: ""

        }),
        success: function (data) {
            warehouses = data;
            sessionStorage.setItem("warehouses", JSON.stringify(data))
        },
    })
}

getOrderDetail();

/*通过订单号获取订单详情*/
function getOrderDetail() {
    $.ajax({
        type: "POST",
        url: root.serviceProviderManagement.getServiceOrderDetail2,
        cache: false, //禁用缓存
        dataType: "json",
        async: false,
        data: {
            "orderId": orderId, // 订单编号
        },
        success: function (results) {
            //详情
            QueryorderDetail(results);

        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            alert(XMLHttpRequest);
        }
    });
}


/*转换状态函数*/
function changeOrderState(orderState) {
    switch (orderState) {
        /*订单状态*/
        case 10:
            return "待确认";
            break;
        case 20:
            return "待审核";
            break;
        case 30:
            return "待配货";
            break;
        case 40:
            return "待出库";
            break;
        case 50:
            return "待发货";
            break;
        case 60:
            return "待收货";
            break;
        case 70:
            return "已收货，待结算";
            break;
        case 80:
            return "已完成";
            break;
        case 90:
            return "交易完成";
            break;
        case 100:
            return "已取消";
            break;
        case 110:
            return "交易关闭";
            break;
    }
}

function calculate(listAddressReceiver, type) {
    var math = ""
    var phone = ""
    var he = ""
    var size = listAddressReceiver.length
    if (listAddressReceiver.length == 0) {
        return "";
    }
    for (i = 0; i < size; i++) {
        if (i < size - 1) {
            math += listAddressReceiver[i].receiverName + " ;"
            phone += listAddressReceiver[i].mobile + " ; "
            if (i % 2 != 0) {
                he += listAddressReceiver[i].receiverName + listAddressReceiver[i].mobile + " ; <br/> "
            } else {
                he += listAddressReceiver[i].receiverName + listAddressReceiver[i].mobile + " ;  "
            }
        } else {
            math += listAddressReceiver[i].receiverName
            phone += listAddressReceiver[i].mobile
            if (i % 2 != 0) {
                he += listAddressReceiver[i].receiverName + listAddressReceiver[i].mobile + "  <br/> "
            } else {
                he += listAddressReceiver[i].receiverName + listAddressReceiver[i].mobile + "   "
            }
        }
    }
    if (type == 1) {
        return math
    } else if (type == 2) {
        return phone
    }
    else if (type == 3) {
        return he
    }
}

function changePayTypeState(payTypeState) {
    switch (payTypeState) {
        /*支付方式*/
        case 1001:
            return "在线支付";
            break;
        case 1002:
            return "支付宝支付";
            break;
        case 1003:
            return "微信支付";
            break;
        case 1101:
            return "货到付款";
            break;
        case 1102:
            return "货到付款-现金";
            break;
        case 1103:
            return "货到付款-pos机";
            break;
        case 1201:
            return "账期支付";
            break;
        case 1301:
            return "银行转账";
            break;
        case 1401:
            return "银行汇票";
            break;
    }
}


function changeDeliveryMethodType(DeliveryMethodType) {
    switch (DeliveryMethodType) {
        /*配送方式*/
        case 10:
            return "鑫方盛物流";
            break;
        case 20:
            return "店内自提";
            break;
    }
}

function changeCopies(is_required, file_copies, original_file) {
    var val

    if (file_copies == 0) {
        val = '不需要资质文件'
        return val
    }

    if (file_copies != 0) {
        val = '需要资质文件&nbsp;&nbsp;&nbsp;&nbsp;'
    } else {
        val = '不需要资质文件&nbsp;&nbsp;&nbsp;&nbsp;'
    }
    if (file_copies >= 4) {
        val += file_copies + '份&nbsp;&nbsp;&nbsp;&nbsp;'
    } else {
        val += file_copies + '份&nbsp;&nbsp;&nbsp;&nbsp;'
    }

    if (original_file == 10) {
        val += '带红章'
    } else if (original_file == 20) {
        val += '不带红章'
    }
    return val;
}


function changeInvoiceType(invoiceType) {
    switch (invoiceType) {
        /*发票类型*/
        case 10:
            return "增值税";
            break;
        case 20:
            return "普税";
            break;
    }
}

function changeCancleReason(cancleReason) {
    switch (cancleReason) {
        /*取消原因*/
        case 10:
            return "订购错误";
            break;
        case 11:
            return "价格高";
            break;
        case 12:
            return "无法满足到货时效";
            break;
        case 13:
            return "支付问题";
            break;
        case 14:
            return "重复下单";
            break;
        case 15:
            return "暂时不需要";
            break;
        case 16:
            return "订单信息有误";
            break;
        case 17:
            return "无货";
            break;
        case 18:
            return "其他";
            break;
        case 19:
            return "商品质量问题";
            break;
        case 20:
            return "价格错误";
            break;
        case 90:
            return "系统自动取消";
            break;
        case 100:
            return "公司产品原因";
            break;
        case 101:
            return "客户原因";
            break;
        case 102:
            return "用户审批驳回取消";
            break;
    }
}

function changeCloseReason(closeReason) {
    switch (closeReason) {
        /*关闭原因*/
        case 10:
            return "商品质量问题";
            break;
        case 20:
            return "大小/型号与商品描述不符";
            break;
        case 30:
            return "颜色/图案与商品描述不符";
            break;
        case 40:
            return "功能/效果与商品描述不符";
            break;
        case 50:
            return "商城发错货";
            break;
        case 60:
            return "少件/漏件";
            break;
        case 70:
            return "多买/买错不想要了";
            break;
        case 80:
            return "到货物流破损";
            break;
        case 90:
            return "发票问题";
            break;
        case 100:
            return "未按约定时间发货";
            break;
        case 110:
            return "其他原因";
            break;
    }
}

/*渲染页面*/

/*头部按钮*/

function affirmMoney() {
    /*确认认款*/
    layer_show("确认收款", "affirmMoneyAlert.html", "600", "300");
}

/*跳转拒收页面*/
function clientRejection(title, url) {
    var index = layer.open({
        type: 2,
        title: title,
        content: url
    });
    layer.full(index);

}

var isIngReturn = false;

function returnGoods(title) {
    if (isIngReturn) {
        return false;
    }
    isIngReturn = true;
    setTimeout(function () {
        var url = "returnGoods.html";
        var index = layer.open({
            type: 2,
            title: title,
            content: url
        });
        layer.full(index);
    }, 200)
}

function detailCancel() {
    sessionStorage.setItem("stater", "1");
    layer_show("提示", "cancleAlert.html", "600", "300");
}

function cancelorder() {
    var orderDetail = JSON.parse(sessionStorage.getItem("serviceProviderorderDetail"));
    var orderState = orderDetail.orderStatus;
        if (orderState == 40) {
            var index = layer.open({
                type: 2,
                title: "拒收-拦截",
                content: "../order/rejectIntercept.html",
            });
            layer.full(index);
        } else {
            layer_show("取消订单", "../order/cancleAlert.html", "600", "300");
        }

}



function renderOrderPage(data) {
    var dataSource = new Array();
    var datas=data
    //table的数据源
    var table; //table对象
    dataSource = [];
    /*商品总金额*/
    $("#goodsAmount").html((datas.goodsTotalAmount).toFixed(2));
    $("#fare").html((datas.actualShippingFee).toFixed(2));
    $("#orderAmount").html((datas.finalTotalAmount).toFixed(2));
    $("#rateTotalAmount").html((datas.rateTotalAmount).toFixed(2));
    //状态
    var order_status = changeOrderState(datas.orderStatus);
    $("#orderState").html(order_status);
    //订单号
    $("#dorderId").html(datas.channelOrderId);
    $("#orderId").html(datas.orderId);
    var d = new Date(datas.createdOrderAt);
    var atq = d.getFullYear() + '-' + (d.getMonth() + 1) + '-' + d.getDate() + ' ' + d.getHours() + ':' + d.getMinutes() + ':' + d.getSeconds();
    $("#creatOrderTime").html(atq);
    $("#creatOrderTimes").html(datas.pushOrderAt);
    $("#orderRemark").html(datas.orderRemark)
    $("#platform").html(datas.platform);
    $("#parentCustomerName").html(datas.parentCustomerName)
    $("#buyerName").html(datas.buyerName);
    $("#providerName").html(datas.providerName);
    $("#customerName").html(datas.customerName);
    $("#orderAccount").html(datas.orderAccount);
    $("#projectName").html(datas.projectName);
    $("#receiver-address").html(datas.receiverProvinceName + "" + datas.receiverCityName + "" + datas.receiverAreaName + "" + datas.receiverTownName + "" + datas.receiverDetailAddress);
    if(data.addressReceiverPOList!=null){
        $("#consignee").html(calculate(data.addressReceiverPOList, 1));
        /*鼠标移出事件*/
        //收货人
        $("#consignee").mouseover(function () {
            $("#mouseBox").show();
            $("#mouseBox").html(calculate(data.addressReceiverPOList, 1));
        }).mouseout(function () {
            $("#mouseBox").hide();
        })
        $("#email").html(datas.customerEmail);
        //手机
        $("#cell-phone-number").html(calculate(data.addressReceiverPOList, 2));
        $("#cell-phone-number").mouseover(function () {
            $("#mouseBoxTwo").show();
            $("#mouseBoxTwo").html(calculate(data.addressReceiverPOList, 3))
        }).mouseout(function () {
            $("#mouseBoxTwo").hide();
        })
    }

    //固话
    $("#linePhone").html(datas.customerLandlinePhone);
    $("#sales-manager").html(datas.salesManager + "&nbsp;&nbsp;" + datas.salesManagerPhone);
    /*支付与配送信息*/
    $("#expressCompany").html(datas.expressCompany);
    if(datas.sentType==10){
        $("#sentType").html('快递');
    }else  if(datas.sentType==40){
        $("#sentType").html('自有车辆');
    }
    if(datas.sentType==10){
        $("#invoice-tyspe").html('快递');
    }else  if(datas.sentType==40){
        $("#invoice-tyspe").html('自有车辆');
    }

    if(datas.paidType=='1201'){
        $("#paidType").html('账期支付');
    }

    $("#invoiceType").html(datas.invoiceType);
    $("#yuncaiShippingFee").html((datas.yuncaiShippingFee).toFixed(2));
    //实际运费
    var actualShippingFee=""
    if(datas.separateShippingFee==10){
        actualShippingFee=(datas.actualShippingFee).toFixed(2) + '元' + '&nbsp;&nbsp;' + "(运费单开)"
    }else if(datas.separateShippingFee==20){
        actualShippingFee=(datas.actualShippingFee).toFixed(2) + '元' + '&nbsp;&nbsp;' + "(运费分摊)"
    }else {
        actualShippingFee=(datas.actualShippingFee).toFixed(2) + '元'
    }
    $("#actualShippingFee").html(actualShippingFee);
    if(datas.paidType=='1201'){
        $("#money-type").html('账期支付');
    }
    $("#channelShippingFee").html((datas.channelShippingFee).toFixed(2));
    $("#dockShippingFee").html((datas.dockShippingFee).toFixed(2));
    $("#orderType").html(datas.orderType)
    $("#wanna_arrived_in").html(datas.wannaArrivedBegin);
    //结算方式
    if(datas.paidType=='1201'){
        $("#settlement-method").html('账期支付');
    }
    $("#predixt-delivery-time").html(datas.mayArrivedBegin);
    $("#finalTotalAmount").html(datas.finalTotalAmount);
    var sendGoodDate=''
    if(datas.sendGoodDate ==10){
        sendGoodDate='任何时间送货'
    }else  if(datas.sendGoodDate ==20){
        sendGoodDate='工作日送货'
    }
    $("#sendGoodDate").html(sendGoodDate);
    var qualityFileRequireds=""
    if (datas.qualityFileRequired==10) {
        qualityFileRequireds="需要"
    }else  if (datas.qualityFileRequired==20) {
        qualityFileRequireds="不需要"
    }
    $("#qualityFileRequired").html(qualityFileRequireds);

    /*商品信息*/
    	dataSource.splice(0, dataSource.length); //清空数组
    if(datas.itemResponseList!=null && datas.itemResponseList!="" ){
        $.each(datas.itemResponseList, function(i, field) {
            var rowData = new Array();
            rowData.push(field.productPic);
            rowData.push(field.skuCode);
            rowData.push(field.productName);
            rowData.push(field.skuInfo);
            rowData.push(field.sendGoodWarehouse);
            rowData.push(field.buyerCount);
            rowData.push(field.unitName);
            rowData.push(field.channelSettledPrice);
            rowData.push(field.settledPrice);
            rowData.push(field.purchasePrice);
            rowData.push(field.freightShare);
            rowData.push(field.productTotolPrice);//小计
            dataSource.push(rowData);
        });
        initDataTable(dataSource);
    }
        function initDataTable(dataSource) {
            var dttable = $('#orderDetailsdatatable').dataTable(); // 初始化dataTable，清空上一个值
            dttable.fnClearTable(); //清空一下table
            dttable.fnDestroy(); //还原初始化了的datatable
            console.log(dataSource);
            $("#orderDetailsdatatable").DataTable({
                "autoWidth": false,
                "ordering": false,
                "searching": false,
                "paging": false,
                "retrieve": false,
                "destroy": true,
                "bAutoWidth": true,
                "bLengthChange": true,
                "aLengthMenu": [5, 10, 25, 50],
                "oLanguage": {
                    "sLengthMenu": "每页显示 _MENU_ 条记录",
                    "sZeroRecords": "抱歉， 没有找到",
                    "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
                    "sInfoEmpty": "没有数据",
                    "sInfoFiltered": "(从 _MAX_ 条数据中检索)",
                    "oPaginate": {
                        "sFirst": "首页",
                        "sPrevious": "前一页",
                        "sNext": "后一页",
                        "sLast": "尾页"
                    },
                    "sZeroRecords": "没有检索到数据",
                    "sProcessing": "<img src='./loading.gif' />"
                },
                data: dataSource,
                columnDefs: [{
                        "visible": true,
                        "targets": 0
                    },
                    {
                        "render": function(data, type, row) {
                                var val = '<div style="cursor:pointer;"><img title="" style="float: left;width: 100px;height: 100px;" name="" src="'+row[0]+'" alt=""><div style="float: left;width:180px;padding-top: 20px;margin-left: 10px;"><div>' + row[1] + '</div><div>' + row[2] + '</div><div>' + row[3] + '</div></div></div>';
                            return val;
                        },
                        "targets": 0
                    },
                    {
                        "render": function(data, type, row) {

                            var val = '<span>' + row[4] + '</span>';
                            return val;
                        },
                        "targets": 1
                    },
                    {
                        "render": function(data, type, row) {
                            var val = '<span>' + row[5] + '' + row[6] + '</span>';
                            return val;
                        },
                        "targets": 2
                    },
                    {
                        "render": function(data, type, row) {
                            var val = '<span>' + (row[7] ).toFixed(2)+ '' + '元' + '</span>';
                            return val;
                        },
                        "targets": 3
                    },
                    {
                        "render": function(data, type, row) {

                            var val = '<span>' +( row[8]).toFixed(2) + '' + '元' + '</span>';
                            return val;
                        },
                        "targets": 4
                    },
                    {
                        "render": function(data, type, row) {
                            var val = '<span>' + row[9] + '' + '元' + '</span>';
                            return val;
                        },
                        "targets": 5
                    },

                    {
                        "render": function(data, type, row) {
                            var val = '<span>' + (row[10]).toFixed(2) + '元' + '</span>';
                            return val;
                        },
                        "targets": 6
                    },
                    {
                        "render": function(data, type, row) {
                            var val = '<span>' + (row[11]).toFixed(2) + '元'+'</span>';
                            return val;
                        },
                        "targets": 7
                    }
                ]
            });
        };


}

/*跳转退货订单详情*/
function returnOrderInfo(title, url, returnId, orderId) {
    sessionStorage.setItem("returnId", returnId);
    sessionStorage.setItem("returnOrderId", orderId);
    var index = layer.open({
        type: 2,
        title: title,
        content: url,
        /* 关闭弹出框的回调函数*/
        end: function () {
            location.replace(location.href)
        }
    });
    layer.full(index);
}



//退货申请单
var isIngReturn = false;

function returnGoods1(title) {
    if (isIngReturn) {
        // layer.msg('请求已提交，请勿重复点击！');
        return false;
    }
    isIngReturn = true;
    getOrderDetail();
    setTimeout(function () {
        var orderDetail = JSON.parse(sessionStorage.getItem("serviceProviderorderDetail"));
        var orderState = orderDetail.orderBase.order_status;

        var url = "orderSuccess_refund2.html";

        var index = layer.open({
            type: 2,
            title: title,
            content: url
        });
        layer.full(index);
    }, 200)
}

//详情信息
function QueryorderDetail(results) {
    result11 = results;
    //收货人信息
    var listAddressReceiverarr = []
    var listAddressReceivers = ""
    if (results.data.receiver != "" && results.data.receiver != null) {

        var listAddressReceiverall = results.data.receiver
        for (var k = 0; k < listAddressReceiverall.length; k++) {

            var information = listAddressReceiverall[k].receiver_name + '&nbsp' + listAddressReceiverall[k].mobile;
            listAddressReceiverarr.push(information);
        }
        for (var j = 0; j < listAddressReceiverarr.length; j++) {
            if (j < listAddressReceiverarr.length - 1) {
                listAddressReceivers += listAddressReceiverarr[j] + "、";
            } else {
                listAddressReceivers += listAddressReceiverarr[j] + "";
            }
        }
        sessionStorage.setItem("listAddressReceivers", listAddressReceivers)
    }
    if(results.data.uploadProofStatus!=""&& results.data.uploadProofStatus!=null){
        uploadProofStatus=results.data.uploadProofStatus
    }
    //经纬度
    var oop = ""
    if (results.data.lat == "" && results.data.lat == null) {
        oop = results.data.lng
    } else if (results.data.lng == "" && results.data.lng == null) {
        oop = results.data.lat
    } else if (results.data.lng == "" || results.data.lng == null && results.data.lat == "" || results.data.lat == null) {
        oop = ""
    } else {
        oop = results.data.lng + ',' + results.data.lat
    }
    $("#lng").html(oop);
    if (results.data.refundList != null && results.data.refundList != "") {
        $("#returnInfoBox").css({
            display: "block"
        });
        var listOrderRefunds = ""
        $.each(results.data.refundList, function (k, v) {
            listOrderRefunds += '<tr><td class="col-2-1">退货单号：<span id="returnId"></span><a onclick="returnOrderInfo(\'退货单详情\',\'../afterSales/afterSales_details.html\',\'' + v.refundId + '\')">' + v.refundId + '</a></td><td class="col-2-1">申请时间：<span id="applytime"></span><span>' + v.createdAt + '</span></td></tr>';
        })
        $("#returnTable").empty().append($(listOrderRefunds))
    }else {
        $("#returnInfoBox").css({
            display: "none"
        });
    }
    var result = results.data;
    sessionStorage.setItem("serviceProviderorderDetail", JSON.stringify(result));
    //详情信息
    renderOrderPage(result);

    switch (result.orderStatus) {
        case 10:
            /*待确认*/

            break;
        /*订单状态*/
        case 20:
            //待审核
            if ( result.isCancelOrder == 0 || result.isCancelOrder == 2 ) {
                $("#cancelorder").css({
                    display: "inline"
                });
            }
            break;
        case 30:
            /*待配货*/
            $("#orderPlacement").css({
                display: "inline"
            });
            $("#placementResults").css({
                display: "inline"
            });

            break;
        case 40:
            /*待出库*/
            $("#orderPlacement").css({
                display: "none"
            });
            $("#placementResults").css({
                display: "none"
            });
            if ( result.isCancelOrder == 0 || result.isCancelOrder == 3 ) {
                $("#cancelorder").css({
                    display: "inline"
                });
            }

            if ( result.orderExt.secondary_sent_type == 10) {

                $("#delivery-method").html("厂家直发");
            } else {

                $("#delivery-method").html(changeDeliverthodType(result.orderExt.sent_type));

            }


        function changeDeliverthodType(DeliveryMethodType) {
            switch (DeliveryMethodType) {
                /*配送方式*/
                case 10:
                    return "快递";
                    break;
                case 20:
                    return "快运-送货上门";
                    break;
                case 30:
                    return "快运-站点自提";
                    break;
                case 40:
                    return "鑫方盛物流";
                    break;
                case 50:
                    return "上门自提";
                    break;
            }
        }

            break;
        case 50:
            /*待发货*/
            if ( result.isCancelOrder == 0 || result.isCancelOrder == 3 ) {
                $("#cancelorder").css({
                    display: "inline"
                });
            }
            break;
        case 60:
            /*待收货*/
            $("#confirmRreceipt").css({
                display: "inline"
            });
            $("#clientRejection").css({
                display: "inline"
            });
            //查看物流信息
            $("#logisticsInformations").css({
                display: "inline"
            });
            //查询退货凭证是否展示
            queryInformation()

            break;
        case 70:
            /*已收货，待结算*/
            $("#returnGoods").css({
                display: "inline"
            });
            //查看物流信息
            $("#logisticsInformations").css({
                display: "inline"
            });
            //查询退货凭证是否展示
            queryInformation()

            break;
        case 80:
            /*订单成功*/

            break;
        case 90:
            /*交易完成*/

            break;
        case 100:
            /*已取消*/

            break;
        case 110:
            /*交易关闭*/

    }
};
//查询退货凭证
function queryInformation() {
    $.ajax({
        contentType: "application/json;charset=UTF-8",
        url: root.serviceProviderManagement.listProof,
        cache: false,  //禁用缓存
        type: "POST",
        dataType: 'json',
        data: JSON.stringify({
            "businessId": orderId, // 订单号
            "proofType":10

        }),
        success: function (results) {
            if(results.data!="" && results.data!=null){

                $("#receiptCertificate").css({
                    display: "inline"
                });
            }else {
                $("#receiptCertificate").css({
                    display: "none"
                });
            }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            alert(XMLHttpRequest);
        }
    });
}

//物流信息查询
var oddnumber = '';//配送单号
function logisticsInformation() {
    $("#logisticsInformation").modal("show")
    /*-------------------------物流轨迹-----------------------*/
    oddnumber = ''
    var express_numall = JSON.parse(sessionStorage.getItem("serviceProviderorderDetail")).expressNum
    if (express_numall != "") {
        var expressNumArr = strReplaceFn(express_numall);
        if (expressNumArr.length > 0) {
            var delivery_numberhtml = '';
            oddnumber = expressNumArr[0];
            $.each(expressNumArr, function (i, item) {
                if (i == 0) {
                    delivery_numberhtml += ' <span class=" delivery_numberactive" oddnumberone="' + item + '" onclick="isclickshow(this)" style="background: rgb(255, 244, 234); border: 1px solid rgb(240, 131, 39); border-radius: 14px; padding: 5px 12px; cursor: pointer; margin-left: 20px;">' + item + '</span>'
                } else {
                    delivery_numberhtml += ' <span class="delivery_number" oddnumberone="' + item + '" onclick="isclickshow(this)" style="background: rgb(247, 247, 247); border: 1px solid rgb(204, 204, 204); border-radius: 14px; padding: 5px 12px; cursor: pointer; margin-left: 20px;">' + item + '</span>'
                }
            })
            $(".delivery_numbercount").html(delivery_numberhtml)
        }
        if (expressNumArr.length > 0) {
            deliveryfn(oddnumber);//页面初始化 调取物流信息 应当传参 配送单号 第一个
        }
    } else {
        $(".logisticsbox").remove();
    }
}

//切换物流信息
function isclickshow(e) {
    oddnumber = $(e).attr('oddnumberone');//配送单号
    var loadingFlag;
    deliveryfn(oddnumber);// 每次点击 传参相对应的 配送单号
    $(e).css({
        'background': '#FFF4EA',
        'border': '1px solid #F08327',
        'border-radius': '14px',
        'padding': '5px 12px',
        'cursor': 'pointer',
        'margin-left': '20px'
    });
    $(e).siblings().css({
        'background': '#F7F7F7',
        'border': '1px solid #CCCCCC',
        'border-radius': '14px',
        'padding': '5px 12px',
        'cursor': 'pointer',
        'margin-left': '20px',
    });
}
// 物流信息
function deliveryfn(numoddnumber) {
    var formData = new FormData();
    formData.append('orderId',orderId);
    formData.append('expressNum',numoddnumber);
    var deliveryhtml = '';
    $.ajax({
        url: root.dockingplatform.queryLogistics,
        type: "POST",
        data: formData,
        cache: false,        // 不缓存数据
        processData: false,  // 不处理数据
        contentType: false,
        success: function (data) {
            if(data.data != null){
                if(data.data.logisticsInfolist == null || data.data.deliverystatus == null){
                    $(".delivery_companybox").addClass('hide');
                    $(".delivery_exhibitioncont").html('暂无物流信息');
                    $(".verify_info.delivery_detailbox").css('text-align', 'center');
                }else{
                    $(".delivery_companybox").addClass('show');
                    if (data.errorCode == 0) {
                        deliverystatusfn(data.data.deliverystatus);
                        $(".delivery_company").html(data.data.expName);//配送公司
                        $(".delivery_status").html(statusdate);//快递状态
                        if (data.data.logisticsInfolist.length > 0) {
                            $.each(data.data.logisticsInfolist, function (i, item) {
                                deliveryhtml += '          <div class="delivery_exhibitionbox">\n';
                                if (i != (data.data.logisticsInfolist.length - 1)) {
                                    deliveryhtml += '            <span class="sepcfix_date ">' + item.time + '</span>\n';
                                } else {
                                    deliveryhtml += '            <span class="sepcfix_date sepcfix_datelast">' + item.time + '</span>\n';
                                }
                                deliveryhtml += '            <span class="sepcfix_detailbox">\n';
                                deliveryhtml += '              <p class="sepcfix_img">\n';
                                if (i == 0) {
                                    deliveryhtml += '                <img src="' + srcimgdate + '" class="signforyesimg"  alt="">\n';
                                    if(data.data.logisticsInfolist.length ==1){
                                        deliveryhtml += ' <span class="vertical_line"></span>\n';
                                    }
                                } else {
                                    if (i != (data.data.logisticsInfolist.length - 1)) {
                                        deliveryhtml += '                <img src="../../../img/signforno_img.png" class="signfornoimg  signfornoimglast"  alt="">\n';
                                    } else {
                                        deliveryhtml += '                <img src="../../../img/signforno_img.png" class="signfornoimg signfornoimgtop"  alt="">\n';
                                    }
                                }
                                if (i != (data.data.logisticsInfolist.length - 1)) {
                                    deliveryhtml += '                <span class="vertical_line"></span>\n';
                                }
                                deliveryhtml += '              </p>\n';
                                deliveryhtml += '            </span>\n';
                                deliveryhtml += '            <span class="sepcfix_luchengbox">\n';
                                if (i == 0) {
                                    deliveryhtml += '<div class="sepcfix_name">' + statusdate + '</div>\n';
                                    deliveryhtml += '              <div class="sepcfix_detail sepcfix_detailtop">' + item.status + '</div>\n';
                                } else {
                                    deliveryhtml += '              <div class="sepcfix_detail sepcfix_detaillast">' + item.status + '</div>\n';
                                }
                                deliveryhtml += '            </span>\n';
                                deliveryhtml += '          </div>';
                            })
                            $(".delivery_exhibitioncont").html(deliveryhtml);
                            $(".verify_info.delivery_detailbox").css('text-align', '');
                            if(data.data.logisticsInfolist.length  == 1){
                                $('span.sepcfix_date.sepcfix_datelast').css('top','-41px');
                            }
                        }
                    }
                }
            }else{
                $(".delivery_companybox").addClass('hide');
                $(".delivery_exhibitioncont").html('暂无物流信息');
                $(".verify_info.delivery_detailbox").css('text-align', 'center');
            }
        },
        error: function () {
            $.Huimodalalert('失败！',2000);
        }
    });

}

var statusdate = '';//物流状态 全局变量
var srcimgdate = '';//图片 全局变量
function deliverystatusfn(status) {/*0：快递收件(揽件)1.在途中 2.正在派件 3.已签收 4.派送失败 5.疑难件 6.退件签收*/
    switch (status) {
        case "0":
            statusdate = "快递收件(揽件)";
            srcimgdate = '../../../img/lanshou-img.png';
            break;
        case "1":
            statusdate = "在途中";
            srcimgdate = "../../../img/signforno_img.png"
        case "2":
            statusdate = "正在派件";
            srcimgdate = "../../../img/peijian-img.png";
            break
        case "3":
            statusdate = "已签收";
            srcimgdate = '../../../img/signforyes_img.png';
            break
        case "4":
            statusdate = "派送失败";
            srcimgdate = "../../../img/signforno_img.png";
            break
        case "5":
            statusdate = "疑难件";
            srcimgdate = "../../../img/signforno_img.png";
            break
        case "6":
            statusdate = "退件签收";
            srcimgdate = "../../../img/signforno_img.png";
            break
    }
}
//查看物流关闭
function closelogisticsInformation() {
    $("#logisticsInformation").modal("hide")
}
//查看收货凭证
function receiptCertificate() {
    $("#receiptCertificates").modal("show")
    if(uploadProofStatus==30||uploadProofStatus==40){
        $(".receiptCertibtn").css({
            display: "none"
        })
    }else {
        $(".receiptCertibtn").css({
            display: "inline-block"
        })

    }
    $.ajax({
        contentType: "application/json;charset=UTF-8",
        url: root.serviceProviderManagement.listProof,
        cache: false,  //禁用缓存
        type: "POST",
        dataType: 'json',
        data: JSON.stringify({
            "businessId": orderId, // 订单号
            "proofType":10

        }),
        success: function (results) {
            var proofUrlsall= results.data[0].proofUrls.split(",");
            var htmls=''
            for (var i=0;i<proofUrlsall.length;i++) {
                htmls+="<span onclick=checkBigPic('"+proofUrlsall[i]+"')>"+
                "<img src='"+proofUrlsall[i]+"' class='ml-10' width='80px' height='80px'>"+
                "</span>"

            }
            $("#proofUrls").html(htmls)

            $("#proofRemark").html(results.data[0].proofRemark)
            orderProofListid=results.data[0].id
            console.log(orderProofListid)
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            alert(XMLHttpRequest);
        }
    });
}

// 点击查看大图
function checkBigPic(imgUrl){
    var title = '查看图片';
    var url = '../../goods/picShow.html';
    window.event ? window.event.cancelBubble = true : e.stopPropagation();
    sessionStorage.setItem("imgUrl", imgUrl);
    layer_show(title, url, "800", "500", '200','100');
}
//查看收货审核通过
function approveds() {

    var cu = layer.confirm('<span>请确认是否审核通过</span>', {title:'提示',btn: ['确认', '取消']}, function(index){
        $.ajax({
            contentType: "application/json;charset=UTF-8",
            url: root.serviceProviderManagement.receiptProofCheckPass,
            cache: false,  //禁用缓存
            type: "POST",
            dataType: 'json',
            data: JSON.stringify({
                "businessId": orderId, // 订单号
                "checkUserId":JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.user_ID,
                "checkUserName":JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.name,
                "id":orderProofListid

            }),
            success: function (results) {
                if(results.code == 0){
                    layer.msg("审核通过成功", {icon: 6, time: 1000}, function () {
                        layer.close(cu);
                        $("#receiptCertificates").modal("hide")
                        location.replace(location.href)

                    });
                } else {
                    layer.msg(results.msg, {icon: 6, time: 1000}, function () {
                        layer.close(cu);
                        $("#receiptCertificates").modal("hide")
                        location.replace(location.href)

                    });
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert(XMLHttpRequest);
            }
        });

    },function(){
        layer.close(cu);
    });
    $(".layui-layer").removeAttr('style')
    $(".layui-layer").attr("style",'z-index: 99999999;top: 174px;left: 731px;')
}
//查看收货审核驳回
function auditRejections() {
    $("#reasonsforrejection").modal("show")
    $("#checkRemark").val("")
}
//驳回确定
function rejectiondetermine() {
    $.ajax({
        contentType: "application/json;charset=UTF-8",
        url: root.serviceProviderManagement.receiptProofReject,
        cache: false,  //禁用缓存
        type: "POST",
        dataType: 'json',
        data: JSON.stringify({
            "businessId": orderId, // 订单号
            "checkUserId":JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.user_ID,
            "checkUserName":JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.name,
            "id":orderProofListid,
            "checkRemark":$("#checkRemark").val()

        }),
        success: function (results) {
            if(results.code == 0){
                layer.msg("凭证已驳回", {icon: 6, time: 1000}, function () {
                    $("#reasonsforrejection").modal("hide")
                    $("#receiptCertificates").modal("hide")
                    location.replace(location.href)

                });
            } else {
                layer.msg(results.msg, {icon: 6, time: 1000}, function () {
                    $("#reasonsforrejection").modal("hide")
                    $("#receiptCertificates").modal("hide")
                    location.replace(location.href)

                });
            }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            alert(XMLHttpRequest);
        }
    });
}
//驳回取消
function rejectioncancel() {
    $("#reasonsforrejection").modal("hide")
}
//下推订单
function pushOrder() {
    $.ajax({
        contentType: "application/json;charset=UTF-8",
        url: root.serviceProviderManagement.orderPush,
        cache: false,  //禁用缓存
        type: "POST",
        dataType: 'json',
        data: JSON.stringify({
            orderId: orderId,
            operatorId: JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.user_ID,
            operatorName: JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.name

        }),
        success: function (data) {
            if (data.code == 0) {
                $.Huimodalalert("订单已加入下推列队，成功与否请稍后查看", 2000);
                pushOrdererrorCode = 0
                getOrderDetail()
            } else {
                $.Huimodalalert(data.msg, 2000);
                pushOrdererrorCode = 1
                getOrderDetail()
            }
        },
        error: function () {
            $.Huimodalalert('失败！', 2000);
        }
    });
}
//下推订单结果
function pushOrder2() {
    $("#pushOrderinformation").modal("show");
    if (pushOrdererrorCode == 1) {
        $("#nos").css({
            display: "inline"
        });
        $("#reasons").html(JSON.parse(sessionStorage.getItem("serviceProviderorderDetail")).pushResultStr)
    } else {
        $("#nos").css({
            display: "none"
        });
        $("#reasons").html("订单已加入下推列队，成功与否请稍后查看")
    }
}
//操作日志
function operationLogInformation() {
    sessionStorage.setItem("serviceProviderIds", orderId)
    var title = "操作日志"
    var url = "operationLogInformation.html"
    var index = layer.open({
        type: 2,
        title: title,
        content: url
    });
    layer.full(index);
}
/*跳转退货订单详情*/
function returnOrderInfo(title, url, returnId,) {
    sessionStorage.setItem("applyNos", returnId);
    var index = layer.open({
        type: 2,
        title: title,
        content: url,
        /* 关闭弹出框的回调函数*/
        end: function () {
            location.replace(location.href)
        }
    });
    layer.full(index);
}
//确认收货
function confirmRreceipt() {
    $.ajax({
        contentType: "application/json;charset=UTF-8",
        url: root.serviceProviderManagement.confirmReceipt,
        cache: false,  //禁用缓存
        type: "POST",
        dataType: 'json',
        data: JSON.stringify({
            "orderId": orderId, // 订单号
            "operateUserId":JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.user_ID,
            "operateUserName":JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.name,
        }),
        success: function (results) {
            if (results.code =='0'){
                layer.msg("确认收货成功", {icon: 6, time: 2000}, function () {
                    location.replace(location.href)
                });
            }else {
                layer.msg(results.msg, {icon: 5, time: 2000}, function () {
                    location.replace(location.href)
                });

            }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            alert(XMLHttpRequest);
        }
    });
}